namespace Velocity4Net.Runtime.Parse.AST
{
    using System;
    using Velocity4Net.Runtime.Parse;
    using MethodInvocationException = Velocity4Net.Errors.MethodInvocationException;
    using ParseErrorException = Velocity4Net.Errors.ParseErrorException;
    using ResourceNotFoundException = Velocity4Net.Errors.ResourceNotFoundException;
    using InternalContextAdapter = Velocity4Net.Ctx.InternalContextAdapter;
    using System.IO;

    /// <summary> This class is responsible for handling the ElseIf VTL control statement.
    ///
    /// Please look at the Parser.jjt file which is
    /// what controls the generation of this class.
    /// *
    /// </summary>
    /// <author> <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    /// </author>
    /// <author> <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
    /// </author>
    /// <version> $Id: ASTElseIfStatement.cs,v 1.3 2003/10/27 13:54:10 corts Exp $
    /// </version>
    public class ASTElseIfStatement : SimpleNode
    {
        public ASTElseIfStatement(int id) : base(id) { }

        public ASTElseIfStatement(Parser p, int id) : base(p, id) { }

        /**
        * An ASTElseStatement is true if the expression
        * it contains evaluates to true. Expressions know
        * how to evaluate themselves, so we do that
        * here and return the value back to ASTIfStatement
        * where this node was originally asked to evaluate
        * itself.
        * @param context
        * @return True if all childs are true.
        * @throws MethodInvocationException
        */
        public override bool Evaluate(InternalContextAdapter context)
        {
            return jjtGetChild(0).Evaluate(context);
        }

        /**
         * @see org.apache.velocity.runtime.parser.node.SimpleNode#render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)
         */
        public override bool Render(InternalContextAdapter context, TextWriter writer)
        {
            return jjtGetChild(1).Render(context, writer);
        }
    }
}
